package com.hhxy.service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet("/AxiosServlet")
public class AxiosServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("doPost方法别调用了");
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("doGet方法被调用了");
        //1、接收请求参数
        String username = request.getParameter("username");

        //解决中文乱码
        byte[] bytes = username.getBytes(StandardCharsets.ISO_8859_1);
        username = new String(bytes,StandardCharsets.UTF_8);


        System.out.println(username);
        //2、响应数据
        response.getWriter().write("Hello Axios!");
    }
}
